#include "cworker_exec.h"

int cworker_exec(wtk_ps_cfg_t *cfg) {
    int ret = -1;
    wtk_ps_t *ps = wtk_ps_new(cfg);
    wtk_strbuf_t *buf = wtk_strbuf_new(cfg->buf_size, cfg->buf_size);

    if (ps) {
        ret = wtk_ps_process(ps, buf, cfg->cmd_fn);
        if (ret) goto end;

        log_i("cmd: %s, ret: %d, result: %s", cfg->cmd_fn, ret, wtk_strbuf_to_str(buf));

        ret = 0;
    }

end:
    if (buf) wtk_strbuf_delete(buf);
    if (ps) wtk_ps_delete(ps);
    return ret;
}
